import React from 'react';
import Taro from '@tarojs/taro';

import { connect } from 'react-redux';
import * as T from './types';
import actions from './actions';
import { store2Props } from './selectors';

import { View, Image, ScrollView, Text } from '@tarojs/components';
import AddressList from './components/AddressList';
import './index.less';
import none from './components/img/none.png';

actions().actions.loadReducer();

// @ts-ignore
@connect<Partial<T.IProps>, any>(store2Props, actions)
export default class AddressD extends React.Component<Partial<T.IProps>, any> {

  // 使用state值
  // constructor(props) {
  //   super(props)
  //   this.state={
  //     test:1
  //   }
  // }

  componentDidShow() {
    // 或取路由值  // eg: { id: 2, type: 'test' }
    // Taro.getCurrentInstance()?.router?.params
    this.props.actions.init()
  }

  componentWillUnmount() {
    this.props.actions.clean();
  }

  render() {
    if (!this.props.main) return null
    let { main: { isLoading, addressList } } = this.props
    console.log(isLoading)

    return (
      <>
        {
          addressList && addressList.length > 0 ?
            <View className="pageAddressD">
              <ScrollView scrollY style={{ overflow: 'hidden' }} >
                <AddressList />
              </ScrollView>
              <View className='props-bottom'>
                <View
                  className="bottom-btn"
                  onClick={() => {
                    Taro.navigateTo({
                      url: '/pages/package-D/addressAdd/index',
                    })
                  }}
                >
                  <Text className="btn-text">添加地址</Text>
                </View>
              </View>
            </View> :
            <View className="pageAddressD" style={{ backgroundColor: '#ffffff' }}>
              <View className="not-orders-list">
                <Image src={none} className="current-none-img" mode="widthFix" />
                <Text className="current-none-text">您还没有添加过地址哦～</Text>
                <View
                  className='orders-btn'
                  onClick={() => {
                    Taro.navigateTo({
                      url: '/pages/package-D/addressAdd/index',
                    })
                  }}>添加地址</View>
              </View >
            </View >
        }
      </>

    );
  }
}
